import dayjs from "dayjs"
import relativeTime from 'dayjs/plugin/relativeTime'
import cn from 'dayjs/locale/zh-cn'

export const formatActivityDate = () => {
	dayjs.extend(relativeTime)
	dayjs.locale(cn)
	return function(item) {
		return dayjs(item.createAt).fromNow()
	}
}

export function formatTime(time) {
	const date = new Date(time)
	const mapDate = {
		year: date.getFullYear(),
		mouth: date.getMonth() + 1,
		day: date.getDate()
	}
	const {mouth,day} = mapDate
	return mouth + '月' + day + '日'
}

export function formatDate(time) {
	const date = new Date(time)
	const mapDate = {
		hour: date.getHours().toString(),
		minutes: date.getMinutes().toString(),
	}
	const {hour,minutes} = mapDate
	return hour + ':' + minutes.padEnd(2, '0')
}

